package com.bweab.controll.depositcontroll;

import com.bweab.service.api.DepositTbServiceInterface;
import com.bweab.service.impl.DepositTbServiceInterfaceImpl;
import com.bweab.util.JSONResult;
import com.bweab.util.JSONStats;
import com.bweab.util.WebUtil;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/despoitMonkey")
public class DespoitMonkey extends HttpServlet {
    //创建service
    DepositTbServiceInterface depositTbService=new DepositTbServiceInterfaceImpl();
    //创建返回结果
    JSONResult jsonResult = new JSONResult();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //用户id
        int userid = Integer.parseInt(req.getParameter("userid"));
        //用户充值金额
        int usermonkey = Integer.parseInt(req.getParameter("usermonkey"));
        //寝室id
        int dormitoryid = Integer.parseInt(req.getParameter("dormitoryid"));
        System.out.println(userid+"-----"+usermonkey+"-------"+dormitoryid);
        //判断用户id是否为空
        if(userid>0 && usermonkey>0 && dormitoryid>0){
            //调用服务层
            int rows = depositTbService.depositMonkey(userid,usermonkey,dormitoryid);
            System.out.println(rows+"结果");
            if(rows>0){
                jsonResult.setStatusCode(JSONStats.DESPOIT_MONKEY_OK.getStatusCode());
                jsonResult.setMessage(JSONStats.DESPOIT_MONKEY_OK.getMessage());
            }else{
                //失败
                jsonResult.setStatusCode(JSONStats.DESPOIT_MONKEY_ERROR.getStatusCode());
                jsonResult.setMessage(JSONStats.DESPOIT_MONKEY_ERROR.getMessage());
            }
        }else {
            //失败
            jsonResult.setStatusCode(JSONStats.DESPOIT_MONKEY_ERROR.getStatusCode());
            jsonResult.setMessage(JSONStats.DESPOIT_MONKEY_ERROR.getMessage());

        }

        WebUtil.writeJson(resp,jsonResult);

    }
}
